package com.linln.admin.app.repository;

import com.linln.admin.app.domain.VersionApp;
import com.linln.common.config.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author taofucheng
 * @date 2021/07/11
 */
public interface VersionAppRepository extends BaseRepository<VersionApp, Long> {
    /**
     * 查询指定版本中的关联项目，有多少合并代码冲突的
     * @param versionId
     * @return
     */
    @Query("select count(t) from #{#entityName} t where version_id=:versionId and (merge_from_status='2' OR merge_to_status='2')")
    int countConflict(@Param("versionId") long versionId);

    @Query("from #{#entityName} t where version_id=:versionId")
    List<VersionApp> findByVersionId(@Param("versionId") Long versionId);

    @Query("select count(t) from #{#entityName} t where version_id=:versionId")
    int countByVersionId(@Param("versionId") Long versionId);

    @Query(nativeQuery = true,value = "SELECT a.* FROM `app_version_app` a,`app_version` b WHERE a.`version_id`=b.`id` AND b.`published`='0' AND b.`status`='1' AND a.`status`='1'")
    List<VersionApp> findAllDevAppAndVersion();
}